package com.czk.model.proxy.cglibproxy;


import org.springframework.cglib.proxy.Enhancer;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/9/14 21:29
 */
public class CglibObjectFactory {
    public static <T> T getProxyObject(Class<T> clazz) {
        // 增强器
        Enhancer enhancer = new Enhancer();
        // 将被代理的类设置为父类
        enhancer.setSuperclass(clazz);
        // 代理代码
        enhancer.setCallback(new CglibProxy());
        // 创建新类
        T t = (T) enhancer.create();
        return t;
    }
}
